package com.google.gwt.sample.dynatablerf.client.theme;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.sample.dynatablerf.client.widgets.GrifoSearchBox;
import com.google.gwt.sample.dynatablerf.client.widgets.GrifoWidgetFactory;
import com.google.gwt.user.cellview.client.DataGrid;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwt.user.client.ui.TabLayoutPanel;

public class GrifoTheme {

	public interface GrifoImageResources extends ClientBundle {

		static final String IMAGES_PATH = "images/";

		public static final GrifoImageResources INSTANCE = GWT
				.create(GrifoImageResources.class);

		@Source(IMAGES_PATH + "iconOk_16x16.png")
		public ImageResource iconOk_16x16();

		@Source(IMAGES_PATH + "iconExit.png")
		public ImageResource iconExit();

		@Source(IMAGES_PATH + "iconProjeto.png")
		public ImageResource iconProjetos();

		@Source(IMAGES_PATH + "iconMaterial.png")
		public ImageResource iconMaterial();

		@Source(IMAGES_PATH + "iconServico.png")
		public ImageResource iconServico();

		@Source(IMAGES_PATH + "iconSetaVerde.png")
		public ImageResource iconSetaVerde();

		@Source(IMAGES_PATH + "iconSetaVermelha.png")
		public ImageResource iconSetaVermelha();

		@Source(IMAGES_PATH + "iconQuadradoVermelho.png")
		public ImageResource iconQuadradoVermelho();

		@Source(IMAGES_PATH + "iconPesquisa.png")
		public ImageResource iconPesquisa();

		@Source(IMAGES_PATH + "iconSetaBaixo.png")
		public ImageResource iconSetaBaixo();

	}

	public static Label getLabelPadrao() {
		Label label = new Label();
		label.setStyleName("grifo-Label");
		return label;
	}

	public static Button getButtonPadrao(Image image, Label label) {
		Button button = GrifoWidgetFactory.getButton(image, label);
		button.setStylePrimaryName("grifo-Button");
		return button;
	}

	public static <T> DataGrid<T> getGridPadrao(Class<T> clazz) {
		DataGrid<T> dataGrid = new DataGrid<T>();
		dataGrid.setStylePrimaryName("grifo-DataGrid");
		return dataGrid;
	}

	public static TabLayoutPanel getTabLayoutPanel() {
		return new TabLayoutPanel(2.5, Unit.EM);
	}

	public static Image getCloseTabImage() {
		Image image = new Image(GrifoImageResources.INSTANCE.iconExit());
		image.setStyleName("grifo-CloseTabButton");
		return image;
	}

	public static Label getLabelDockTeste() {
		Label label = new Label();
		label.setStylePrimaryName("grifo-DockTeste");
		return label;
	}

	public static SimplePager getSimplePager() {
		SimplePager pager = new SimplePager();
		pager.addStyleName("grifo-Pager");
		return pager;
	}

	public static HorizontalPanel getFatorPanel() {
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setStyleName("grifo-fatorPanel");
		return horizontalPanel;
	}

	private static MenuBar getSearchOptionsHeader() {

		MenuBar menu = new MenuBar();
		menu.setStyleName("grifo-MenuBar");
		menu.setWidth("500px");

		return menu;
	}

	public static MenuBar getSearchOptionsMenu(MenuBar searchMenu) {
		MenuBar menu = new MenuBar(true);
		menu.setStyleName("grifo-MenuSearchOptions");

		Button searchButton = GrifoWidgetFactory.getButton(new Image(
				GrifoImageResources.INSTANCE.iconSetaBaixo()));

		MenuItem menuItem = GrifoWidgetFactory.getMenuItem(searchButton, menu);
		menuItem.setStylePrimaryName("grifo-SearchOptionsButton");
		menu.setAnimationEnabled(true);

		searchMenu.addItem(menuItem);
		return menu;
	}

	public static MenuItem getSearchOptionsItem(String text, Command cmd) {
		MenuItem item = new MenuItem(text, cmd);
		item.setStyleName("grifo-MenuSearchOptionsItem");
		return item;
	}

	public static GrifoSearchBox getSearchBox(SuggestOracle suggestOracle) {

		SuggestBox suggestBox = new SuggestBox(suggestOracle);
		suggestBox.setStyleName("grifo-SearchTextBox");

		GrifoSearchBox grifoSearchBox = new GrifoSearchBox(suggestBox,
				getSearchOptionsHeader());
		grifoSearchBox.setStylePrimaryName("grifo-SearchBox");

		return grifoSearchBox;
	}
}
